/**
 * 桨模 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-18 22:28:43
 */
layui.use(['jquery','febs', 'form', 'validate', 'fileUpload'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#modelOars-detail'),
        fileUpload = layui.fileUpload,
        laydate = layui.laydate,
        validate = layui.validate;

    form.verify(validate);
    form.render();

    initFormValue();

    function initFormValue() {
        if (modelOarsData) {
            form.val("modelOars-detail-form", {
                "id": modelOarsData.id,
                "oarsCode": modelOarsData.oarsCode,
                "projectCode": modelOarsData.projectCode,
                "oarsName": modelOarsData.oarsName,
                "source": modelOarsData.source,
                "status": modelOarsData.status,
                "demandEnddate": modelOarsData.demandEnddate,
                "actuallyStartdate": modelOarsData.actuallyStartdate,
                "actuallyEnddate": modelOarsData.actuallyEnddate,
                "makeModelFile": modelOarsData.makeModelFile,
                "waterDate": modelOarsData.waterDate,
                "position": modelOarsData.position,
                "diameter": modelOarsData.diameter,
                "pitch": modelOarsData.pitch,
                "surfaceRate": modelOarsData.surfaceRate,
                "chordLength": modelOarsData.chordLength,
                "fanThick": modelOarsData.fanThick,
                "holeDiameter": modelOarsData.holeDiameter,
                "shellLength": modelOarsData.shellLength,
                "frontDiameter": modelOarsData.frontDiameter,
                "backendDiameter": modelOarsData.backendDiameter,
                "oarsType": modelOarsData.oarsType,
                "prupose": modelOarsData.prupose,
                "oarsDiameter": modelOarsData.oarsDiameter,
                "fanNumber": modelOarsData.fanNumber,
                "memo": modelOarsData.memo,
                "origOarsCode": modelOarsData.origOarsCode,
            });

            if(modelOarsData.source){
                changeSource(modelOarsData.source.toString());
            }

        }
    }

    var fileUploadDiv = fileUpload.render({
        elem: '#fileUpload',
        url: ctx + 'upload/file',
        type: 2,//0-图片，1-视频，2-其他
        maxNum:5,
        defaultData: getFileList(),
        isDetail: true,
        done: function (res) {
        },
    });

    function changeSource(val){
        if(val === '2'){
            $('#origOarsCodeDiv').show();
        }else{
            $('#origOarsCodeDiv').hide();
        }
    }

    function getFileList() {
        if (attachs && attachs.length>0) {
            return  attachs;
        }else {
            return  [];
        }
    }

    $('#reset').click(function () {
        closeCur();
    });

    function closeCur(){
        var currentUrl = window.location.hash.replace('#', '');
        febs.view.tab.del(currentUrl);
        febs.view.tab.change("/modelOars");
        $('#febs-modelOars').find('#query').trigger('click');
    }

});